﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Millionaire;
using WindowsFormsApplication1.BLL;

namespace WindowsFormsApplication1.UI.UC
{
    public partial class UcThongKe : UserControl
    {
        LinhVucBLL linhVucBLL;

        public UcThongKe()
        {
            InitializeComponent();
            linhVucBLL = new LinhVucBLL();
            LoadDataToCmbLinhVuc();
        }

        private void LoadDataToCmbLinhVuc()
        {
            List<LinhVuc> dsLinhVuc = linhVucBLL.GetAll();
            dsLinhVuc.Insert(0, new LinhVuc() { MaLinhVuc = 0, TenLinhVuc = "Tat ca" });
            cmbLinhVuc.DisplayMember = "TenLinhVuc";
            cmbLinhVuc.ValueMember = "MaLinhVuc";
            cmbLinhVuc.DataSource = dsLinhVuc;
                
        }

        private void cmbLinhVuc_SelectedIndexChanged(object sender, EventArgs e)
        {
            int maLv = (int) cmbLinhVuc.SelectedValue;
            LoadDataToDgvThongKe(maLv);
        }

        private void LoadDataToDgvThongKe(int maLv)
        {
            CauHoiBLL cauHoiBLL = new CauHoiBLL();
            if(maLv != 0)
                dgvThongKe.DataSource = from ds in cauHoiBLL.ThongKeCauHoi(maLv)
                                        orderby ds.Key
                                        select new { Key = ds.Key, Value = ds.Value };
            else
                dgvThongKe.DataSource = from ds in cauHoiBLL.ThongKeCauHoi()
                                        orderby ds.Key
                                        select new { Key = ds.Key, Value = ds.Value };
        }

       
    }
}
